﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Storage;
using SmartWMS.Common.Extensions;
using SmartWMS.Common.ResponseOutput;
using SmartWMS.Domain.Base;
using SmartWMS.Domain.BusinessManage;
using SmartWMS.Domain.SystemSet;
using SmartWMS.Server.BusinessServer.SalesManagementService;
using SmartWMS.Server.BusinessServer.SalesManagementService.Dto;
using System.Collections.Generic;

namespace SmartWMS.API.Controllers.BusinessMange
{
	/// <summary>
	/// 销售管理控制器
	/// </summary>
	[Route("api/[controller]/[action]")]
	[ApiController]
	[ApiExplorerSettings(GroupName = "Business")]
	public class SalesManagementController : ControllerBase
	{
		private readonly ISalesManagementService _salesManagement;

		public SalesManagementController(ISalesManagementService salesManagement)
		{
			_salesManagement = salesManagement;
		}

		/// <summary>
		/// 显示销售管理
		/// </summary>
		/// <param name="dto">要查询的Dto对象</param>
		/// <returns></returns>
		[HttpPost]
		public IActionResult GetSalesManagementDtoAsync(SearchSalesManagementDto dto)
		{
			try
			{
				var pageObj = _salesManagement.GetSalesManagementDtoAsync(dto);
				return Ok(new
				{
					pageObj.Result.totalCount,
					pageObj.Result.pageCount,
					data = pageObj.Result.data
				});
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 删除销售管理
		/// </summary>
		/// <param name="info"></param>
		/// <returns></returns>
		[HttpPost]
		public Task<Response<bool>> DelSalesManagement(SalesManagementDtoInpute info)
		{
			try
			{
				var result = _salesManagement.DelSalesManagement(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 批量删除销售管理
		/// </summary>
		/// <param name="info"></param>
		/// <returns></returns>
		[HttpPost]
		public Task<Response<bool>> BatchDelSearchSalesManagement(SalesManagementDtoInpute dto)
		{
			try
			{
				var result = _salesManagement.BatchDelSearchSalesManagement(dto);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 查看销售管理
		/// </summary>
		/// <param name="info">要查看的销售管理</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<FillSalesManagement1Dto>> FillSalesManagement1Async(FillSalesManagement1Dto info)
		{
			try
			{
				var result = await _salesManagement.FillSalesManagement1Async(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 查看销售下的产品管理
		/// </summary>
		/// <param name="info"></param>
		/// <returns></returns>
		//[HttpPost]
		//public Task<Response<List<FileSalesManagement2Dto>>> FileSalesManagement2DtoAsync(FileSalesManagement2Dto info)
		//{
		//	try
		//	{
		//		var result = _salesManagement.FileSalesManagement2DtoAsync(info);
		//		return result;
		//	}
		//	catch (Exception)
		//	{
		//		throw;
		//	}
		//}

		/// <summary>
		/// 添加销售管理 + 产品列表
		/// </summary>
		/// <param name="info">要添加的销售管理实体</param>
		/// <returns></returns>
		//[HttpPost]
		//public async Task<Response<bool>> AddSalesManagement(AddSalesManagementDto info)
		//{
		//	try
		//	{
		//		var result = await _salesManagement.AddSalesManagement(info);
		//		return result;
		//	}
		//	catch (Exception)
		//	{
		//		throw;
		//	}
		//}

		/// <summary>
		/// 销售编号
		/// </summary>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<List<SaleDtos>>> BindSale()
		{
			var result = await _salesManagement.BindSale();
			return result;
		}
		/// <summary>
		/// 智能联想框
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public Task<Response<CustomsDtos>> GetCustomByCode(SaleDtos dto)
		{
			var result = _salesManagement.GetCustomByCode(dto);
			return result;
		}

		/// <summary>
		/// 销售管理是否退货
		/// </summary>
		/// <param name="info"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> IsReturnSearchSalesManagement(SalesManagementDtoInpute info)
		{
			try
			{
				var resuilt = await _salesManagement.IsReturnSearchSalesManagement(info);
				return resuilt;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 销售管理是否入账
		/// </summary>
		/// <param name="info"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> IsRecordedSearchSalesManagement(SalesManagementDtoInpute info)
		{
			try
			{
				var result = await _salesManagement.IsRecordedSearchSalesManagement(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 添加销售管理 + 产品列表
		/// </summary>
		/// <param name="info">要添加的销售管理实体</param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> AddSalesManagement(AddSalesManagementDto info)
		{
			try
			{
				var result = await _salesManagement.AddSalesManagement(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}

		/// <summary>
		/// 销售退货
		/// </summary>
		/// <param name="info"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<Response<bool>> RefunAdd(SalesReturnDto info)
		{
			try
			{
				var result = await _salesManagement.RefunAdd(info);
				return result;
			}
			catch (Exception)
			{
				throw;
			}
		}
	}
}
